package ch9;

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class AddCloth {
	public static void main(String[] args) throws Exception {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(new File("src/ch9/clothes.xml"));
		Element root = doc.getRootElement();
		Element newCloth = root.addElement("cloth");
		// Scanner in = new Scanner(System.in);
		newCloth.addAttribute("chandi", "安徽合肥");
		newCloth.addAttribute("color", "黑");
		Element b = newCloth.addElement("brand");
		b.setText("伊尔美");
		Element p = newCloth.addElement("price");
		p.setText("55.6");
		Element s = newCloth.addElement("suit");
		s.setText("老少皆宜");
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("utf-8");
		XMLWriter xm = new XMLWriter(new FileWriter("src/ch9/clothes.xml"), format);
		xm.write(doc);
		xm.close();
	}
}
